package com.lanhe.app.controller.order;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSON;
import com.lanhe.common.constant.Constants;
import com.lanhe.common.core.controller.BaseController;
import com.lanhe.common.core.domain.AjaxResult;
import com.lanhe.common.core.page.TableDataInfo;
import com.lanhe.common.utils.StringUtils;
import com.lanhe.order.domain.LhOrdersHaoka;
import com.lanhe.order.domain.LhOrdersKayu;
import com.lanhe.order.domain.dto.LhOrdersKayuApplyDto;
import com.lanhe.order.service.ILhOrdersKayuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * 卡鱼-订单
 *
 * @author zhanggl
 * @date 2023年12月22日21:15:40
 */
@RestController
@RequestMapping("/api/kayu/orders")
@Slf4j
public class ApiLhOrdersKayuController extends BaseController {

	@Resource
	private ILhOrdersKayuService ordersKayuService;


	/**
	 * 分页查询所有数据
	 */
	@GetMapping("/list")
	public TableDataInfo list(LhOrdersKayu ordersKayu) {
		startPage();
		ordersKayu.setMemberId(getUserId());
		List<LhOrdersKayu> list = ordersKayuService.selectOrdersList(ordersKayu);
		for (LhOrdersKayu lhOrdersHaoka : list) {
			lhOrdersHaoka.setStatusName(Constants.HaokaOrderStatus.getHaokaOrderStatusName(lhOrdersHaoka.getStatus()));
		}
		return getDataTable(list);
	}


	/**
	 * 新增数据（卡鱼进件）
	 *
	 * @param applyDto 实体对象
	 * @return 新增结果
	 */
	@PostMapping("/add")
	public AjaxResult add(@RequestBody LhOrdersKayuApplyDto applyDto) throws Exception {

		log.info("ApiLhOrdersKayuController--->add 卡鱼进件入参：【{}】", JSON.toJSONString(applyDto));
		if (StringUtils.isBlank(applyDto.getUserKey())) {
			return error("用户标识为必须条件");
		}
		if (ObjectUtil.isNull(applyDto.getProductId())) {
			return error("产品ID为必须条件");
		}
		if (ObjectUtil.isNull(applyDto.getUsername())) {
			return error("用户名为必须条件");
		}
		if (ObjectUtil.isNull(applyDto.getPhone())) {
			return error("手机号为必须条件");
		}
		if (ObjectUtil.isNull(applyDto.getIdNo())) {
			return error("证件号为必须条件");
		}
		return toAjax(ordersKayuService.insertOrdersKayu(applyDto));
	}

	/**
	 * 卡鱼进件-回调通知
	 *
	 * @param params 实体对象
	 * @return 结果
	 */
	@PostMapping("/merchantApplyNotice")
	public Object settlementNotice(@RequestBody Map<String, String> params) throws Exception {
		log.info("ApiLhOrdersKayuController--->merchantApplyNotice 卡鱼：【{}】", JSON.toJSONString(params));
		ordersKayuService.settlementNotice(params);
		return "success";
	}
}

